package models

import (
	"log"
	"time"
)

type CoachCert struct {
	Id      int       `xorm:"not null pk autoincr comment('自增主键') INT(11)" json:"id"`
	CoachId int       `xorm:"not null comment('教练员id外键关联dts_coach表中的id') index INT(11)" json:"coach_id"`
	IdCard  string    `xorm:"comment('身份证') index VARCHAR(255)" form:"id_card" json:"id_card"`
	IdCardB string    `xorm:"comment('身份证背面') index VARCHAR(255)" form:"id_card_b" json:"id_card_b"`
	DirLic  string    `xorm:"comment('驾驶证') index VARCHAR(255)" form:"dir_lic" json:"dir_lic"`
	DirLicB string    `xorm:"comment('驾驶证背面') index VARCHAR(255)" form:"dir_lic_b" json:"dir_lic_b"`
	Acc     string    `xorm:"comment('无事故证明') index VARCHAR(255)" form:"acc" json:"acc"`
	Prove   string    `xorm:"comment('运管同意证明') index VARCHAR(255)" form:"prove" json:"prove"`
	AddTime time.Time `xorm:"comment('') DATETIME" json:"add_time"`
}

func (c *CoachCert) GetByCoachId(coach int) (ok bool, list CoachCert, err error) {
	if ok, err = engine.Table("dts_coach_cert").Where("coach_id=?", coach).Get(&list); err != nil {
		return ok, list, err
	}
	return ok, list, nil
}

func (c *CoachCert) Edit(id int, field ...string) bool {
	var (
		err error
	)
	_, err = engine.Table("dts_coach_cert").Where("coach_id = ?", id).Cols(field...).Update(c)
	if err != nil {
		log.Print(err)
		return false
	}
	return true
}
